package com.dk.controller;

import com.dk.pojo.TabCategory;
import com.dk.service.CategoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.annotation.ModelAttributeMethodProcessor;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @RequestMapping("tolist")
    public String category() {
        return "category/show";
    }

    @RequestMapping("selectserver")
    @ResponseBody
    public Map<String, Object> selectserver(String cname, @RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "3") Integer pageSize) {

        Map<String, Object> map = new HashMap<>();
        PageInfo<TabCategory> category = categoryService.selectserver(cname, pageNumber, pageSize);
        map.put("total", category.getTotal());
        map.put("rows", category.getList());
        return map;
    }

    @RequestMapping("insertInto")

    public String insertInto() {
        return "category/add";
    }

    @RequestMapping("insertADD")
    @ResponseBody
    public boolean insertADD(TabCategory c) {
        boolean a = categoryService.insertInfo(c);
        return a;
    }

    @RequestMapping("huixuan")
    public String huixuan(Integer cid, Model mo) {
        TabCategory a = categoryService.selectBcid(cid);
        mo.addAttribute("c", a);
        return "category/update";
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public boolean updateInfo(TabCategory t) {
        boolean a = categoryService.updateInfo(t);
        return a;
    }

    @RequestMapping("empdelete")
    @ResponseBody
    public boolean empdelete(Integer id) {
        boolean a = categoryService.deleteById(id);
        return a;
    }
    @RequestMapping("deleteshanchu")
    @ResponseBody
    public boolean deleteshanchu(@RequestParam("ids") Integer[] ids){
           boolean a =  categoryService.deleteshanchu(ids);
        return  a;
    }
}
